package com.frxuexi.shop2307.view

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.lib_base.utils.ArouterManager
import com.frxuexi.lib_base.utils.GlideUtils
import com.frxuexi.shop2307.R
import com.frxuexi.shop2307.adapter.PinAdapter
import com.frxuexi.shop2307.databinding.ActivityPinBinding
import com.youth.banner.loader.ImageLoader
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/PinActivity")
class PinActivity : BaseActivity<ActivityPinBinding,PinViewModel>() {
    val pinAdapter by lazy { PinAdapter() }
    override fun initData() {
        vm.getPinShopsData.observe(this){
            pinAdapter.apply {
                addData(it.list)
                notifyDataSetChanged()
            }
        }


    }

    override fun initView() {
        val imgs= listOf<String>("http://10.161.9.80:8080/crmebimage/public/maintain/2021/12/25/7a6475bba07c47bb98e5db0e0d21c8ebq5sw2kijlc.jpg",
            "http://10.161.9.80:8080/crmebimage/public/maintain/2021/12/25/37382cca048b4011bdbacd3cbbe0814daw1o5x0tco.jpg",
            "http://10.161.9.80:8080/crmebimage/public/maintain/2021/12/25/fef1aee22a04466d93693f5791d44bfd2rsm469mcr.jpg",
            "http://10.161.9.80:8080/crmebimage/public/maintain/2021/12/25/f65ef5469f3a479497a710fb288d115cvl5imkvpo8.jpg",
            "http://10.161.9.80:8080/crmebimage/public/maintain/2021/12/25/3ed152917e3f4f7faa9414050b6cab49vuadulntb8.jpg",
        )
        binding.pinBanner.apply {
            setImages(imgs)
            setImageLoader(object: ImageLoader(){
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    GlideUtils.getImage(imageView!!,path.toString())
                }
            })
            start()
        }

        vm.getPinShops()
        binding.pinRv.apply {
            adapter=pinAdapter
            layoutManager=LinearLayoutManager(this@PinActivity)
        }

        pinAdapter.setOnItemClickListener { adapter, view, position ->
            ArouterManager.nav(this,"/app/PinDetailActivity",pinAdapter.data.get(position).id)
        }

        binding.pinBack.setOnClickListener {
            finish()
        }
    }

}